package com.database.daos.imp;

import java.util.List;

import org.springframework.transaction.annotation.*;

import com.database.daos.IProjectDao;
import com.database.objects.Project;

public class ProjectDao extends GenericDao<Project> implements IProjectDao {

	private static final long serialVersionUID = 1004180493271405983L;

	@Override
	@SuppressWarnings("unchecked")
	public List<Project> findByAll() {
		return findByNamedQuery("Project.findByAll");
	}

	@Override
	@SuppressWarnings("unchecked")
	@Transactional(propagation = Propagation.REQUIRED)
	public Project getByName(String name) {
		List<Project> projects = findByNamedQueryAndNamedParam("Project.getByName", "name", name);
		Project project = projects.isEmpty() ? null : projects.get(0);
		initialize(project);
		return project;
	}

	public void initialize(Project project) {
		if (project != null) {
			initialize(project.getDevelopers());
		}
	}

}